import api from '@/api/index.js'
import  * as CONSTANT from '../constant.js'

export const getAllArticlesAction = (page) => {
    return async (dispatch) => {
        const response = await api.article.getAllArticles(page)
        if (response && response.status !== 1) {
            throw new Error(response.message)
        }
        const {count, articles} = response.data;
        dispatch({type: CONSTANT.ARTICLES_SYNC, payload: {count, articles, currentPage: page}})
    }
}
export const getTagArticlesAction = (tag,page) => {
    return async (dispatch) => {
        const response = await api.article.getTagArticles(tag,page)
        if (response && response.status !== 1) {
            throw new Error(response.message)
        }
        const {count,articles} = response.data;
        dispatch({type:CONSTANT.ARTICLES_SYNC,payload:{count,articles,currentPage:page}})
    }
}